package com.mmy.dao.car;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.car.VCarPlan;

public interface VCarPlanRepository extends JpaRepository<VCarPlan, Integer> {

	/*
	 * 根据ScenicID查找
	 */
	@Query(value = "select *  from vCarPlan where iCarID = :iCarID", nativeQuery = true)
	List<VCarPlan> findByCarID(@Param("iCarID") int iCarID);

	/*
	 * 根据ID查找
	 */
	@Query(value = "select *  from vCarPlan where iPlanID = :iPlanID", nativeQuery = true)
	VCarPlan findByID(@Param("iPlanID") int iPlanID);
	
	/**
	 * 前台预留--通过carID和时间查询对应计划
	 * 
	 * @return 返回值说明 iPlanID
	 * @author 创建人 liys
	 * @date 创建日期 2020.11.16
	 */
	@Query(value = "select iPlanID from vCarPlan where iCarID = :iCarID and :date between date_format(dStartDate,'%Y-%m-%d') and date_format(dEndDate,'%Y-%m-%d')", nativeQuery = true)
	int findPlanById(@Param("iCarID")int iCarID,@Param("date") Date date);
}
